function buildHandle(storage: Storage) {
  return {
    get: function (target: any, prop: string) {
      const str = storage.getItem(prop);
      let obj = { value: '' };
      try {
        obj = JSON.parse(str as any) || obj;
      } catch (e) {}
      return obj.value;
    },
    set: function (target: any, prop: string, value: any) {
      Reflect.set(target, prop, value);
      storage.setItem(prop, JSON.stringify({ value }));
      return true;
    },
  };
}

export const $local = new Proxy({}, buildHandle(localStorage));
export const $session = new Proxy({}, buildHandle(sessionStorage));
export const $cache={};